﻿using Testflow.Data;

namespace Testflow.SlaveCore.Runner.Convertors
{
    internal class ByteConvertor : ValueConvertorBase
    {
        protected override void InitializeConvertFuncs()
        {
            ConvertFuncs.Add(typeof (decimal).Name, sourceValue => System.Convert.ToDecimal((byte)sourceValue));
            ConvertFuncs.Add(typeof (double).Name, sourceValue => System.Convert.ToDouble((byte)sourceValue));
            ConvertFuncs.Add(typeof (float).Name, sourceValue => System.Convert.ToSingle((byte)sourceValue));
            ConvertFuncs.Add(typeof (long).Name, sourceValue => System.Convert.ToInt64((byte)sourceValue));
            ConvertFuncs.Add(typeof (ulong).Name, sourceValue => System.Convert.ToUInt64((byte)sourceValue));
            ConvertFuncs.Add(typeof (int).Name, sourceValue => System.Convert.ToInt32((byte)sourceValue));
            ConvertFuncs.Add(typeof (uint).Name, sourceValue => System.Convert.ToUInt32((byte)sourceValue));
            ConvertFuncs.Add(typeof (short).Name, sourceValue => System.Convert.ToInt16((byte)sourceValue));
            ConvertFuncs.Add(typeof (ushort).Name, sourceValue => System.Convert.ToUInt16((byte)sourceValue));
            ConvertFuncs.Add(typeof (char).Name, sourceValue => System.Convert.ToChar((byte)sourceValue));
//            ConvertFuncs.Add(typeof (byte).Name, sourceValue => System.Convert.ToByte((byte)sourceValue));
            ConvertFuncs.Add(typeof (bool).Name, sourceValue => (byte)sourceValue > 0);
            ConvertFuncs.Add(typeof (string).Name, sourceValue => sourceValue.ToString());
        }

        public override object GetDefaultValue()
        {
            return (byte) 0;
        }
    }
}